/**
 * Created by henian.xu on 2018/11/22.
 *
 */

const { Builder } = require('nuxt');

module.exports = app => {
    app.beforeStart(async () => {
        const isDev = app.config.env === 'local';
        try {
            if (isDev) {
                const nuxtBuilder = new Builder(app.nuxt);
                await nuxtBuilder.build();

                console.log('[nuxt] Build Success.');
            }
        } catch (error) {
            console.log('[nuxt] Building Error:', error);
            process.exit(1);
        }
    });
};
